package com.sky.mapper.common;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface DishMapper {

    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> findBySetmealId(Long id);

    /**
     * 动态条件查询菜品
     * @param dish
     * @return
     */
    List<Dish> selectByNameStatusCategoryId(Dish dish);

    @AutoFill(OperationType.UPDATE)
    int update(Dish dish);

    DishVO selectDishAndFlavorsById(Long id);
    /**
     * 根据菜品id和状态查询数量
     *
     * @param
     * @return
     */
    Integer selectCountByIdsAndStatus(@Param("ids") List<Integer> ids,
                                      @Param("status") Integer status);
    //批量删除菜品
    void deleteByIds(@Param("ids") List<Integer> ids);
    /**
     * 菜品分页查询
     *
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);
    /**
     * 增加
     * @param dish
     * @return
     */
    @AutoFill(OperationType.INSERT)
    int insert(Dish dish);

    /**
     * 根据名称统计菜品数量
     * @param name
     * @return
     */
    @Select("select count(id) from dish where name = #{name}")
    Long countByName(String name);
    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

}